<%@ page contentType="text/html; charset=utf-8"%>
<%@ include file="/WEB-INF/jsp/includeTaglib.jsp" %>







<p>分配门店</p>
<div>
	<table id="tableData" border="0" class="dbborder globalText" width="100%" style="margin-left: 25px;" >
		<tr style="text-align: center;">
			<td>门店编号</td>
			<td>门店名称</td>
			<td>操作</td>
		</tr>
		<c:forEach var="projectStore" items="${preAssigned}" varStatus="status">
			<tr height="25px;" class="rowClass">
				<td>${projectStore.channel.code}</td>
				<td>${projectStore.channel.name}</td>
				<td><font class="assigned" storeId="${projectStore.id}"  onclick="unbindWithSpecifiedAssignedStore(${projectStore.id})" color="red" style="cursor: pointer;" >取消</font></td>
			</tr>
		</c:forEach>
		<c:forEach var="projectStore" items="${canBeAssigned}" varStatus="status">
			<tr height="25px;" class="rowClass">
				<td>${projectStore.channel.code}</td>
				<td>${projectStore.channel.name}</td>
				<td><font onclick="assignStoresToProjectEmployee(${projectStore.id})" color="green" style="cursor: pointer;" >分配</font></td>
			</tr>
		</c:forEach>
	</table>
</div>

<script>
	function assignStoresToProjectEmployee(storeId){
		if(!confirm('确认操作?')){
			return;
		}
		
		var storeIds=storeId+";";
		$('.assigned').each(function(){
			storeIds+=$(this).attr('storeId')+";";
		});
		
		
		$.getJSON("<c:url value ='/project/assignStoresToProjectEmployee.html'/>?projEmpId="+projEmpId+"&storeIds="+storeIds, function(jsonData){
			if(jsonData.ok){
				findPreAssignedUserStores(empId,'${projectId}');
			}
		});
	}
	
	function unbindWithSpecifiedAssignedStore(storeId){
		if(!confirm('确认操作?')){
			return;
		}
		$.getJSON("<c:url value ='/project/unbindWithSpecifiedAssignedStore.html'/>?projEmpId="+projEmpId+"&storeId="+storeId, function(jsonData){
			if(jsonData.ok){
				findPreAssignedUserStores(empId,'${projectId}');
			}
		});
	}
	
	$("#tableData").tablesorter( {sortList: [[0,0], [1,0]]} ); 
</script>